<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="数据日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dataDt">
              <j-date placeholder="请选择数据日期" v-model="model.dataDt"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="客户代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="khdm">
              <a-input v-model="model.khdm" placeholder="请输入客户代码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="金融机构代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jrjgdm">
              <a-input v-model="model.jrjgdm" placeholder="请输入金融机构代码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="客户证件类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="khzjlx">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择客户证件类型"
                v-model="model.khzjlx"
                dict="llbb_param_config,name,code"
                pidValue="2eb99a6c4d204f998cbb2781620be14d"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="客户证件代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="khzjdm">
              <a-input v-model="model.khzjdm" placeholder="请输入客户证件代码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="国籍" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="gj">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择国籍"
                v-model="model.gj"
                dict="jrsj_gjdqcode_config,name,code"
                pidValue="234f83f0a30c46a3853ad5f62b99fffb"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="民族" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mz">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择民族"
                v-model="model.mz"
                dict="llbb_param_config,name,code"
                pidValue="dbc886bf932d4f4ca53dc0ef413aa06e"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="性别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="xb">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择性别"
                v-model="model.xb"
                dict="llbb_param_config,name,code"
                pidValue="573838dc0f8e4b849198fcc11967e4e5"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="最高学历" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zgxl">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择最高学历"
                v-model="model.zgxl"
                dict="llbb_param_config,name,code"
                pidValue="b2aa1338bba344809209a038e7e40a79"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="出生日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="csrq">
              <j-date placeholder="请选择出生日期" v-model="model.csrq"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="地区代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dqdm">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择地区代码"
                v-model="model.dqdm"
                dict="jrsj_xzqhdm_config,name,code"
                pidValue="1"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="个人年收入" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="grnsr">
              <a-input-number v-model="model.grnsr" placeholder="请输入个人年收入" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="家庭年收入" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jtnsr">
              <a-input-number v-model="model.jtnsr" placeholder="请输入家庭年收入" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="婚姻情况" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="hyqk">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择婚姻情况"
                v-model="model.hyqk"
                dict="llbb_param_config,name,code"
                pidValue="29d16c70ef7c4f1998237bd333f324f0"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="是否关联方" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sfglf">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择是否关联方"
                v-model="model.sfglf"
                dict="llbb_param_config,name,code"
                pidValue="1486500350999949313"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="授信额度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sxed">
              <a-input-number v-model="model.sxed" placeholder="请输入授信额度" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="已用额度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="yyed">
              <a-input-number v-model="model.yyed" placeholder="请输入已用额度" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="个人客户身份标识" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="grkhsfbs">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择个人客户身份标识"
                v-model="model.grkhsfbs"
                dict="llbb_param_config,name,code"
                pidValue="3fd16b7e984840acba7dd861255338b6"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="个体工商户营业执照代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="gtgshyyzzdm">
              <a-input v-model="model.gtgshyyzzdm" placeholder="请输入个体工商户营业执照代码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="小微企业统一社会信用代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="xwqytyshxydm">
              <a-input v-model="model.xwqytyshxydm" placeholder="请输入小微企业统一社会信用代码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="客户信用级别总等级数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="khxyjbzdjs">
              <a-input-number v-model="model.khxyjbzdjs" placeholder="请输入客户信用级别总等级数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="客户信用评级" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="khxypj">
              <a-input-number v-model="model.khxypj" placeholder="请输入客户信用评级" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="内部机构号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="nbjgh">
              <a-input v-model="model.nbjgh" placeholder="请输入内部机构号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="客户名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="khmc">
              <a-input v-model="model.khmc" placeholder="请输入客户名称"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'JsCdIndCustomersForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 7 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           guid: [
              { required: true, message: '请输入主键!'},
           ],
        },
        url: {
          add: "/jsCdIndCustomers/jsCdIndCustomers/add",
          edit: "/jsCdIndCustomers/jsCdIndCustomers/edit",
          queryById: "/jsCdIndCustomers/jsCdIndCustomers/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.guid){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }

        })
      },
    }
  }
</script>
